# 高阶函数
# 接收函数作为参数,或者将函数作为返回值的函数是高阶函数
# 当我们使用一个函数作为参数时,实际上是将指定的代码传递进了目标函数

# 创建列表
localList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]


def function1(i):
    if i % 2 == 0:
        return True
    return False


def function2(i):
    if i > 5:
        return True
    return False


def function4(function, list):
    # 创建新列表
    evenList = []

    # 对列表进行筛选
    for n in list:
        # 判断奇数偶数
        if function1(n):
            evenList.append(n)

    return evenList


def function5(i):
    return i % 3 == 0


def function6(a, b):
    return a + b


print(function4(function5, localList))

function7 = lambda a, b: a + b
print(function7(10, 30))

function8 = filter(lambda i: i > 5, localList)
print(list(function8))

function9 = map(lambda i: i ** 2, localList)
print(list(function9))

localList = ['aa', 'bbbb', 'ccc', 'dddd', 'ff']
localList.sort(key=len)
print(localList)

localList = [2, 5, '1', 3, '6', '4']
localList.sort(key=int)
print(localList)

# localList = [2, 5, '1', 3, '6', '4']
localList = "123765816742634781"
print('排序前:', localList)
print(sorted(localList, key=int))
print('排序后:', localList)
